home *** CD-ROM | disk | FTP | other *** search
AMOS Source Code | 1992-02-26 | 16.5 KB | 705 lines |
- ' Phone_numbers.Amos - Sept. 94
-
- ' Steve Pullinger
-
- ' This needs AMOSPro!!
-
- ' This is a simple database for phone numbers allowing a search
- ' by name.
-
- ' The actual data handling is very simple, the bulk of the code
- ' is for the Interface requesters.
-
- ' Notice that most of the variables used in the program are locally shared
- ' between the procedures that have authority to modify them.
-
- ' Set Up
- ' ======
- Dir$="Pro_Progs1:Programs/Interface" : Rem Replace this with your own path
-
- ' Global Constants
- ' ================
- Global MX_RECORDS
-
- MX_RECORDS=30
-
- ' Global Variables
- ' ================
- Global MARK_END
-
- MARK_END=0
-
- ' Shared Variables
- ' ================
- Dim NAME$(MX_RECORDS),NUMBER$(MX_RECORDS)
- CHANGE_DATA=False
-
- INITIALISE
-
- ' Main Program Loop
- ' =================
- MENU
- Cls 0
- TERMINATE
-
- ' Procedure Definitions
- ' =====================
- Procedure MENU
- ' This procedure displays a menu of options for a phone number
- ' database
-
- ' Interface Program
- A$=""
- A$=A$+"BAse 123,20 ;"
- A$=A$+"SIze 384,160 ;"
- A$=A$+"SAve 1 ;"
- A$=A$+"BOx 0,0,67,384,160 ;"
-
- ' Program Name
- A$=A$+"LIne 48,24,31,336 ;"
- A$=A$+"POutline 1VACentreX,10,1VA,0,3 ;"
- A$=A$+"LIne 48,40,31,336 ;"
-
- ' Menu Title
- A$=A$+"POutline 2VACentreX,30,2VA,0,3 ;"
-
- ' Browse Option
- A$=A$+"BUtton 1,48,50,288,16,0,0,1;[LI 0,0,BP3*88+,288;PO 3VACentreXBP+,4,3VA,0,3;][ButtonReturn 0;]KY 66,0;"
-
- ' Add Record
- A$=A$+"BUtton 2,48,70,288,16,0,0,1; [LI 0,0,BP3*88+,288;PO 4VACentreXBP+,4,4VA,0,3;][ButtonReturn 0;]KY 65,0;"
-
- ' Delete Record
- A$=A$+"BUtton 3,48,90,288,16,0,0,1;[LI 0,0,BP3*88+,288;PO 5VACentreXBP+,4,5VA,0,3;][ButtonReturn 0;]KY 68,0;"
-
- ' Search
- A$=A$+"BUtton 4,48,110,288,16,0,0,1;[LI 0,0,BP3*88+,288;PO 6VACentreXBP+,4,6VA,0,3;][ButtonReturn 0;]KY 83,0;"
-
- ' Quit
- A$=A$+"BUtton 5,48,130,288,16,0,0,1;[LI 0,0,BP3*88+,288;PO 7VACentreXBP+,4,7VA,0,3;][ButtonReturn 0;]KY 81,0;"
-
- ' End of Interface Program
- 'A$=A$+"RUn 0,0;"
- A$=A$+"EXit ;"
-
-
- ' Open Communication Channel between Amos and Interface program
- Dialog Open 2,A$
-
- Gosub VARS
-
- ' Call Interface Program
- X=Dialog Run(2)
-
- Repeat
- SELECTED=Dialog(2)
- Dialog Freeze 2
-
- ' Call Chosen Option
- ' ==================
- If SELECTED=1
- If MARK_END=0
- MESSAGE["No Records to Browse!",100]
- Else
-
- BROWSE
- End If
- End If
-
- If SELECTED=2
- If MARK_END>=MX_RECORDS
- MESSAGE["Database Is Full!!",100]
- Else
- Inc MARK_END
- AD_RECORD["","",MARK_END]
- Gosub VARS
- X=Dialog Run(2)
- End If
- End If
-
- If SELECTED=3
- DELETE_RECORD
- Gosub VARS
- X=Dialog Run(2)
- End If
-
- If SELECTED=4
- SEARCH
- Gosub VARS
- End If
-
- Dialog Unfreeze 2
- Until SELECTED=5
-
- ' Close Interface program
- Dialog Close(2)
- Pop Proc
-
- VARS:
- ' Send defaults to Interface
- Vdialog$(2,1)="Steve's Phone Numbers"
- If MARK_END=1
- R$=" Record"
- Else
- R$=" Records"
- End If
- Vdialog$(2,2)=Str$(MARK_END)+R$+" in Memory"
- Vdialog$(2,3)="Browse Through Records"
- Vdialog$(2,4)="Add One Record"
- Vdialog$(2,5)="Delete Records"
- Vdialog$(2,6)="Search"
- Vdialog$(2,7)="Quit"
- Return
-
- End Proc
-
- Procedure INITIALISE
- Shared NAME$(),NUMBER$()
-
- ' Initialise Interface resources
- Load "AMOSPro_System:APSystem/AMOSPro_Default_resource.abk"
- Resource Bank 16
- Resource Screen Open 0,640,200,0
- Flash Off : Curs Off : Cls 0 : Paper 0 : Pen 7
- Wait Vbl
-
- ' Check for existing data file
- ' ============================
- If Exist("Phone.dat")
- ' Load Data
- ' =========
- Open Random 1,"Phone.dat"
- Field 1,50 As IN_NAME$,20 As IN_NUM$
- Get 1,1
- MARK_END=Val(IN_NUM$)
-
- ' Read until end of file
- ' ======================
- For RECORD=2 To MARK_END+1
- Get 1,RECORD
- NAME$(RECORD-1)=IN_NAME$
- NUMBER$(RECORD-1)=IN_NUM$
- Next RECORD
-
- Close 1
-
- End If
-
- End Proc
-
- Procedure BROWSE
- Shared NAME$(),NUMBER$()
-
- ' Interface Program
- A$=""
- A$=A$+"BAse 80,30 ;"
- A$=A$+"SIze 384,120 ;"
- A$=A$+"SAve 1 ;"
- A$=A$+"BOx 0,0,67,384,120 ;"
-
- ' Title
- A$=A$+"LIne 48,24,31,336 ;"
- A$=A$+"POutline 7VACentreX,10,7VA,0,3 ;"
- A$=A$+"LIne 48,40,31,336 ;"
-
- ' Record Number
- A$=A$+"POutline 8VACentreX,30,8VA,0,3 ;"
-
- ' Display Name
- A$=A$+"POutline 18,50,5VA,0,3 ;"
-
- ' Display Number
- A$=A$+"POutline 18,70,6VA,0,3 ;"
-
- ' Previous Option
- A$=A$+"BUtton 1,48,90,48,16,0,0,1;[LI 0,0,BP3*88+,48;PO 8BP+,4,1VA,0,3;][ButtonReturn 0;]KY 80,0;"
-
- ' Next Option
- A$=A$+"BUtton 2,108,90,48,16,0,0,1;[LI 0,0,BP3*88+,48;PO 6BP+,4,2VA,0,3;][ButtonReturn 0;]KY 78,0;"
-
- ' Edit Option
- A$=A$+"BUtton 3,238,90,48,16,0,0,1;[LI 0,0,BP3*88+,48;PO 3BP+,4,3VA,0,3;][ButtonReturn 0;]KY 69,0;"
-
- ' Ok Option
- A$=A$+"BUtton 4,292,90,48,16,0,0,1;[LI 0,0,BP3*88+,48;PO 4BP+,4,4VA,0,3;][ButtonReturn 0;]KY 79,0;"
-
-
- ' End of Interface Program
- A$=A$+"EXit ;"
-
- ' Open Communication Channel between Amos and Interface program
- Dialog Open 3,A$
- REC_NO=1
- Gosub VARS
-
- ' Call Interface Program
- X=Dialog Run(3)
-
- ' Check Option
- Repeat
- SELECTED=Dialog(3)
-
- If SELECTED=1
- ' Previous
- If REC_NO>1
-
- Dec REC_NO
- Dialog Freeze 3
- Gosub VARS
- X=Dialog Run(3)
- End If
- End If
-
- If SELECTED=2
- ' Next
- If REC_NO<MARK_END
- Inc REC_NO
- Dialog Freeze 3
- Gosub VARS
- X=Dialog Run(3)
- End If
- End If
-
- If SELECTED=3
- ' Edit Record
- Dialog Freeze 3
- Dialog Clr 3
-
- AD_RECORD[NAME$(REC_NO),NUMBER$(REC_NO),REC_NO]
- Gosub VARS
- X=Dialog Run(3)
- End If
-
- Until SELECTED=4
-
- ' Close Interface program
- Dialog Close(3)
-
- Pop Proc
-
- VARS:
- ' Send defaults to Interface
- Vdialog$(3,1)="Prev"
- Vdialog$(3,2)="Next"
- Vdialog$(3,3)="Edit"
- Vdialog$(3,4)=" Ok "
- Vdialog$(3,5)="Name: "+NAME$(REC_NO)
- Vdialog$(3,6)="Tel: "+NUMBER$(REC_NO)
- Vdialog$(3,7)="Browse Records"
- Vdialog$(3,8)="Current Record:"+Str$(REC_NO)
- Return
-
- End Proc
-
- Procedure AD_RECORD[DEF_NAME$,DEF_NUM$,REC_NO]
- Shared NAME$(),NUMBER$(),TEMP_NAME$,TEMP_NUM$,CHANGE_DATA
-
- RECORD_REQUESTER[DEF_NAME$,DEF_NUM$,"Record No:"+Str$(REC_NO)]
-
- CHANGE_DATA=True
- Repeat
-
- If TEMP_NAME$=""
- RECORD_REQUESTER["",TEMP_NUM$,"Please Enter Name for Record No:"+Str$(REC_NO)]
- End If
-
- If TEMP_NUM$=""
- RECORD_REQUESTER[TEMP_NAME$,"","Please Enter Number for Record No:"+Str$(REC_NO)]
- End If
-
- ' Validate string for numbers, spaces or hyphens only
- ' ===================================================
- If TEMP_NUM$>""
- F=1
- _VALID=True
-
- Repeat
- CH$=Mid$(TEMP_NUM$,F,1)
-
- If((CH$<"0") or(CH$>"9")) and(CH$<>" ") and(CH$<>"-")
- _VALID=False
- End If
-
- Inc F
- Until F>Len(TEMP_NUM$)
-
- If Not _VALID
- TEMP_NUM$=""
- End If
-
- End If
-
- Until(TEMP_NAME$<>"") and(TEMP_NUM$<>"")
-
- NAME$(REC_NO)=TEMP_NAME$
- NUMBER$(REC_NO)=TEMP_NUM$
-
- End Proc
-
- Procedure DELETE_RECORD
- Shared CHANGE_DATA,NAME$(),NUMBER$()
-
- ' Ask Delete All, One Record, or Cancel
-
- ' Interface Program
- A$=""
- A$=A$+"BAse 123,20 ;"
- A$=A$+"SIze 384,160 ;"
- A$=A$+"SAve 1 ;"
- A$=A$+"BOx 0,0,67,384,160 ;"
-
-
- A$=A$+"SetVar 2,'Delete Records' ;"
- A$=A$+"SetVar 3,'Delete ALL Records' ;"
- A$=A$+"SetVar 4,'Delete ONE Record' ;"
- A$=A$+"SetVar 5,'Cancel' ;"
-
- ' Menu Title
- A$=A$+"POutline 2VACentreX,30,2VA,0,3 ;"
-
- ' Delete All Option
- A$=A$+"BUtton 1,48,50,288,16,0,0,1;[LI 0,0,BP3*88+,288;PO 3VACentreXBP+,4,3VA,0,3;][ButtonReturn 0;]KY 65,0;"
-
- ' Delete One Record
- A$=A$+"BUtton 2,48,70,288,16,0,0,1; [LI 0,0,BP3*88+,288;PO 4VACentreXBP+,4,4VA,0,3;][ButtonReturn 0;]KY 79,0;"
-
- ' Cancel
- A$=A$+"BUtton 3,48,90,288,16,0,0,1;[LI 0,0,BP3*88+,288;PO 5VACentreXBP+,4,5VA,0,3;][ButtonReturn 0;]KY 67,0;"
-
- ' End of Interface Program
- A$=A$+"EXit ;"
-
- ' Open Communication Channel
- Dialog Open 1,A$
-
- ' Call Interface Program
- X=Dialog Run(1)
-
- Repeat
- SELECTED=Dialog(1)
- Dialog Freeze 1
-
- ' Delete All
- If SELECTED=1
- CONFIRM_ACTION["This will erase ALL data, are you sure?"]
- If Param=1
- MARK_END=0
- CHANGE_DATA=True
- Vdialog$(2,2)=Str$(MARK_END)+" Records in Memory"
- End If
- End If
-
- ' Delete One Record
- If SELECTED=2
- T_REQUEST["Enter Record Number to delete"]
- REC_NO=Val(Param$)
-
- If(REC_NO>0) and REC_NO<=MARK_END
- SH0W_RECORD[NAME$(REC_NO),NUMBER$(REC_NO),"Record"+Str$(REC_NO)+" Selected for Deletion"]
- CONFIRM_ACTION["Delete Record No."+Str$(REC_NO)+"?"]
-
- If Param=1
- For COUNT=REC_NO To MARK_END-1
- NAME$(COUNT)=NAME$(COUNT+1)
- NUMBER$(COUNT)=NUMBER$(COUNT+1)
- Next COUNT
- Dec MARK_END
- CHANGE_DATA=True
- End If
-
- Vdialog$(2,2)=Str$(MARK_END)+" Records in Memory"
- End If
- End If
-
- Dialog Unfreeze 1
- Until SELECTED=3
-
- ' Close Interface program
- Dialog Close(1)
-
- End Proc
-
- Procedure CONFIRM_ACTION[TITLE$]
- ' Interface Program
- A$=""
- A$=A$+"BAse 80,20 ;"
- A$=A$+"SIze 384,100 ;"
- A$=A$+"SAve 1 ;"
- A$=A$+"BOx 0,0,67,384,100 ;"
-
- A$=A$+"SetVar 3,'Yes, Continue' ;"
- A$=A$+"SetVar 4,'NO, CANCEL!!' ;"
-
- ' Confirm Title
- A$=A$+"POutline 2VACentreX,30,2VA,0,3 ;"
-
- ' Yes Option
- A$=A$+"BUtton 1,48,50,288,16,0,0,1;[LI 0,0,BP3*88+,288;PO 3VACentreXBP+,4,3VA,0,3;][ButtonReturn 0;]KY 89,0;"
-
- ' NO Option
- A$=A$+"BUtton 2,48,70,288,16,0,0,1; [LI 0,0,BP3*88+,288;PO 4VACentreXBP+,4,4VA,0,3;][ButtonReturn 0;]KY 78,0;"
-
-
- ' End of Interface Program
- 'A$=A$+"RUn 0,0;"
- A$=A$+"EXit ;"
-
- ' Open Communication Channel
- Dialog Open 3,A$
-
- ' Set Variables
- Vdialog$(3,2)=TITLE$
-
- ' Call Interface Program
- X=Dialog Run(3)
-
- Repeat
- SELECTED=Dialog(3)
- Until(SELECTED=1) or(SELECTED=2)
-
- ' Close Interface program
- Dialog Close(3)
-
- End Proc[SELECTED]
-
- Procedure RECORD_REQUESTER[DEF_NAME$,DEF_NUM$,TITLE$]
- ' This procedure displays an Interface requester allowing input
- ' of a name and a phone number
-
- Shared TEMP_NAME$,TEMP_NUM$
-
- ' Interface Program
- A$=""
- A$=A$+"BAse 160,50 ;"
- A$=A$+"SIze 384,100 ;"
- A$=A$+"SAve 1 ;"
- A$=A$+"BOx 0,0,67,384,100 ;"
- A$=A$+"SetVar 1,'Enter Record Details' ;"
- A$=A$+"SetVar 2,'Name:' ;"
- A$=A$+"SetVar 3,'Tel.:' ;"
-
- ' Title
- A$=A$+"LIne 48,24,31,336 ;"
- A$=A$+"POutline 1VACentreX,10,1VA,0,3 ;"
- A$=A$+"LIne 48,40,31,336 ;"
-
- ' Record Number
- A$=A$+"POutline 6VACentreX,30,6VA,0,3 ;"
-
- ' Name Gadget
- A$=A$+"POutline 18,50,2VA,0,3 ;"
- A$=A$+"EDit 1,70,50,32,31,4VA,0,5 ;"
-
- ' Number Gadget
- A$=A$+"POutline 18,70,3VA,0,3 ;"
- A$=A$+"EDit 2,70,70,20,19,5VA,0,5 ;"
-
- A$=A$+"BUtton 3,346,80,32,16,0,0,1;[UN 0,0,16;][ButtonQuit;]"
-
- ' End of Interface Program
- A$=A$+"EXit ;"
-
- ' Open Communication Channel between Amos and Interface program
- Dialog Open 1,A$
- Dialog Clr 1
- ' Send defaults to Interface
- Vdialog$(1,4)=DEF_NAME$
- Vdialog$(1,5)=DEF_NUM$
- Vdialog$(1,6)=TITLE$
-
- ' Call Interface Program
- X=Dialog Run(1)
-
- For GADGET=1 To 2
- Repeat
- ' Store Gadgets in strings
- TEMP_NAME$=Rdialog$(1,1)
- TEMP_NUM$=Rdialog$(1,2)
-
- Until Dialog(1)
- Next GADGET
-
- ' Close Interface program
- Dialog Close(1)
-
- End Proc
-
- Procedure SEARCH
- Shared NAME$(),NUMBER$()
-
- ' Search Spec
- ' ===========
- T_REQUEST["Enter name to search for"]
- FIND$=Param$
-
- If FIND$>""
-
- ' Search array
- ' ============
- NO_FOUND=0
- For RECORD=1 To MARK_END
-
- If Instr(Left$(Upper$(NAME$(RECORD)),Len(FIND$)),Upper$(FIND$))
- SH0W_RECORD[NAME$(RECORD),NUMBER$(RECORD),"Record No"+Str$(RECORD)]
- Inc NO_FOUND
- End If
-
- Next RECORD
-
- If NO_FOUND=0
- MESSAGE["No Match Found!",100]
- Else
- MESSAGE["Search Complete",100]
- End If
- End If
-
- End Proc
-
- Procedure T_REQUEST[TITLE$]
-
- ' This procedure displays an Interface requester centred on-screen
- ' The title for the requester is passed as TITLE$ and the procedure
- ' returns the text input from an Interface EDit zone
-
- ' EXAMPLE: REQUEST["Please enter some text"]
-
- ' Interface Program
-
- IN_STRING$=IN_STRING$+"BAse 80,40;"
- IN_STRING$=IN_STRING$+"SIze 1VATextWidth32+,TextHeight6*;"
- IN_STRING$=IN_STRING$+"BAse ScreenWidth SizeX-2/,ScreenHeight SizeY-2/;"
- IN_STRING$=IN_STRING$+"SAve 1;"
- IN_STRING$=IN_STRING$+"BOx 0,0,67,SizeX,SizeY;"
- IN_STRING$=IN_STRING$+"POutline 1VACentreX,10,1VA,0,3;"
- IN_STRING$=IN_STRING$+"ED 1,16,32,2VA,30,'',0,3 ;"
- IN_STRING$=IN_STRING$+"EXit;"
-
-
- ' Open Communication Channel between Amos and Interface program
- Dialog Open 4,IN_STRING$
-
- ' Pass title string to Interface
- TITLE$=" "+TITLE$
- TITLE$=TITLE$+" "
- Vdialog$(4,1)=TITLE$
- Vdialog(4,2)=Len(TITLE$)
-
- ' Call GET_STRING$ program
- X=Dialog Run(4)
-
- ' Wait for input complete
- Repeat
- ' RET$ is returned by the procedure to Amos
- RET$=Rdialog$(4,1)
- Until Dialog(4)
-
- ' Close Interface program
- Dialog Close(4)
-
- End Proc[RET$]
-
- Procedure SH0W_RECORD[SEARCH_NAME$,FOUND_NUM$,TITLE$]
-
- ' Interface Program
- A$=""
- A$=A$+"BAse 100,70 ;"
- A$=A$+"SIze 384,100 ;"
- A$=A$+"SAve 1 ;"
- A$=A$+"BOx 0,0,67,384,100 ;"
- A$=A$+"SetVar 1,'Record Details' ;"
- A$=A$+"SetVar 2,'Name:' ;"
- A$=A$+"SetVar 3,'Tel.:' ;"
-
- ' Title
- A$=A$+"LIne 48,24,31,336 ;"
- A$=A$+"POutline 1VACentreX,10,1VA,0,3 ;"
- A$=A$+"LIne 48,40,31,336 ;"
-
- ' Record Number
- A$=A$+"POutline 6VACentreX,30,6VA,0,3 ;"
-
- ' Name Gadget
- A$=A$+"POutline 18,50,2VA,0,3 ;"
- A$=A$+"POutline 70,50,4VA,0,3 ;"
-
- ' Number Gadget
- A$=A$+"POutline 18,70,3VA,0,3 ;"
- A$=A$+"POutline 70,70,5VA,0,3 ;"
-
- 'A$=A$+"BUtton 3,346,80,32,16,0,0,1;[UN 0,0,16;][ButtonQuit;]"
-
- A$=A$+"RUn 0,%1111;"
- A$=A$+"EXit;"
-
- ' Open Communication Channel between Amos and Interface program
- Dialog Open 5,A$
-
- ' Send defaults to Interface
- Vdialog$(5,4)=SEARCH_NAME$
- Vdialog$(5,5)=FOUND_NUM$
- Vdialog$(5,6)=TITLE$
-
- ' Call Interface Program
- X=Dialog Run(5)
-
- ' Close Interface program
- Dialog Close(5)
-
- End Proc
-
- Procedure MESSAGE[MESSAGE$,DELAY]
- ' Interface Program
-
- A$=A$+"BAse 80,40;"
- A$=A$+"SIze 1VATextWidth32+,TextHeight4*;"
- A$=A$+"BAse ScreenWidth SizeX-2/,ScreenHeight SizeY-2/;"
- A$=A$+"SAve 1;"
- A$=A$+"BOx 0,0,67,SizeX,SizeY;"
- A$=A$+"POutline 1VACentreX,12,1VA,0,3;"
- A$=A$+"RUn 2VA, %1111;"
- A$=A$+"EXit;"
-
-
- ' Open Communication Channel between Amos and Interface program
- Dialog Open 1,A$
-
- ' Pass title string to Interface
- MESSAGE$=" "+MESSAGE$
- MESSAGE$=MESSAGE$+" "
- Vdialog$(1,1)=MESSAGE$
- Vdialog(1,2)=DELAY
-
-
- ' Call GET_STRING$ program
- X=Dialog Run(1)
-
- ' Close Interface program
- Dialog Close(1)
-
- End Proc
-
- Procedure TERMINATE
- Shared NAME$(),NUMBER$(),CHANGE_DATA
-
- If CHANGE_DATA
- ' Save Data to File
- ' =================
- Open Random 1,"Phone.dat"
- Field 1,50 As OUT_NAME$,20 As OUT_NUM$
-
- OUT_NAME$="START OF FILE"
- OUT_NUM$=Str$(MARK_END)
- Put 1,1
-
- For RECORD=2 To MARK_END+1
- OUT_NAME$=NAME$(RECORD-1)
- OUT_NUM$=NUMBER$(RECORD-1)
- Put 1,RECORD
- Next RECORD
-
- Close(1)
-
- MESSAGE["Data Saved",150]
- End If
-
- End Proc